package com.sgcc.fj.pmos.e_fj_personalcenter.activity;

import android.text.TextUtils;
import android.view.View;

import com.alibaba.android.arouter.facade.annotation.Route;
import com.alibaba.android.arouter.launcher.ARouter;
import com.chad.library.adapter.base.BaseQuickAdapter;
import com.sgcc.fj.pmos.arouter.mall.MallArouterPath;
import com.sgcc.fj.pmos.arouter.personalcenter.PersonalCenterArouterPath;
import com.sgcc.fj.pmos.common.base.MvpBaseRecycleActivity;
import com.sgcc.fj.pmos.common.bean.PackageBean;
import com.sgcc.pmos.nativesdk.R;
import com.sgcc.fj.pmos.e_fj_personalcenter.adapter.CollectionAdapter;
import com.sgcc.fj.pmos.e_fj_personalcenter.bean.CollectionBean;
import com.sgcc.fj.pmos.e_fj_personalcenter.contract.CollectionContract;
import com.sgcc.fj.pmos.e_fj_personalcenter.presenter.CollectionPresenter;


/**
 * 收藏列表
 */
@Route(path = PersonalCenterArouterPath.PERSONALCENTER_COLLECTION)
public class CollectionActivity extends MvpBaseRecycleActivity<PackageBean, CollectionPresenter> implements CollectionContract.View {

    private static final String TAG = "CollectionActivity";

    private CollectionAdapter mCollectionAdapter;

    @Override
    public String getTitleText() {
        return "我的收藏";
    }

    @Override
    public void querySuccess(CollectionBean response) {
        dismissLoading();
        if (response != null) {
            if (response.getCode() == 200) {
                if (response.getRows() != null) {
                    loadSuccess(false, response.getRows());
                }
            } else {
                loadFalied();
            }
        }
    }

    @Override
    protected void initViews() {
        super.initViews();
        title_bar.setRightIcon(R.mipmap.go_main, new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                goMainActivity();
            }
        });
    }

    @Override
    public void queryFailed() {
        loadFalied();
    }

    @Override
    public void deleteSuccess() {
        refresh(false);
    }

    @Override
    public void deleteFailed() {

    }

    @Override
    protected CollectionPresenter createPresenter() {
        return new CollectionPresenter();
    }

    @Override
    public BaseQuickAdapter getAdapter() {
        mCollectionAdapter = new CollectionAdapter(mContext);
        mCollectionAdapter.setOnItemClickListener(new CollectionAdapter.OnItemClickListener() {
            @Override
            public void itemClickListener(int position, PackageBean bean) {
                ARouter.getInstance()
                        .build(MallArouterPath.MALL_PACKAGEDETAILS)
                        .withString("combName", bean.getCombCode())
                        .withBoolean("isBlue", "1".equals(bean.getpNum()) && ("03".equals(bean.getMainType()) || "04".equals(bean.getMainType())) &&
                                "0".equals(bean.getMainItemType()) &&
                                ("0".equals(bean.getMainDifType()) || TextUtils.isEmpty(bean.getMainDifType())))

                        .navigation();
            }

            @Override
            public void onDeletePKClickListener(int position, PackageBean bean) {
                String guid = bean.getGuid();
                showLoading();
                mPresenter.onDeletePk(guid, false);
            }
        });
        return mCollectionAdapter;
    }

    @Override
    public void getDataRequest(int listSize, boolean isloading) {
        super.getDataRequest(listSize, isloading);
        mPresenter.getCollectionList(listSize, isloading);
    }
}
